import dayjs from "dayjs";

/**
 * 兼容多种常见时间字段名，返回格式化后的时间字符串
 * @param record 文章对象或包含时间字段的对象
 * @param format 格式化字符串，默认 'YYYY-MM-DD HH:mm:ss'
 */
export function formatDateTime(
  record: any,
  format: string = "YYYY-MM-DD HH:mm:ss"
): string {
  if (!record) return "-";
  const createdAt =
    record.createdAt ||
    record.CreatedAt ||
    record.create_time ||
    record.created_time ||
    record.ctime ||
    record.time ||
    record.date;
  return createdAt ? dayjs(createdAt).format(format) : "-";
} 